<?php
require_once 'DatabaseConfig.php';
/**
 * PDO interface
 * */
class Db
{
	private static $db = NULL;

	/**
	 * only a instance
	 * @return PDO
	 * */

	public static function init()
	{
		if (NULL === self::$db)
		{
			try {
				$dsn = 'mysql:host = '.DB_HOST.';dbname='.DB_NAME.';charset=UTF-8';
				self::$db = new PDO($dsn, DB_USER, DB_PASSWORD);
				self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
				self::$db->setAttribute(PDO::MYSQL_ATTR_LOCAL_INFILE, true);
			} catch (PDOException $e) {
				// exception handler
				// echo "An Error occured!"; //user friendly message
				// die('Connection error: ' . $e->getMessage());
				throw $e;
			}
		}
		return self::$db;
	}
}
?>

